package main

import (
	"gitee.com/huanfion/urlshortener/config"
	_ "gitee.com/huanfion/urlshortener/config"
	"gitee.com/huanfion/urlshortener/internal/router"
	"github.com/gin-gonic/gin"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"
)

func main() {
	cfg := config.Cfg
	engine := gin.Default()

	router.Routers(engine)
	// 启动 HTTP 服务
	go func() {
		if err := engine.Run(":" + cfg.Server.Port); err != nil {
			log.Fatal(err.Error())
		}
	}()
	// 创建一个通道，用于接收停止信号
	stopChan := make(chan os.Signal, 1)
	signal.Notify(stopChan, syscall.SIGINT, syscall.SIGTERM)
	// 主循环，检查停止信号
	for {
		select {
		case <-stopChan:
			return
		default:
			time.Sleep(100 * time.Millisecond)
		}
	}
}
